package org.boun.swe.ARCEONE.Utility;

import java.util.ArrayList;
import java.util.List;

import org.boun.swe.ARCEONE.R;
import org.boun.swe.ARCEONE.Data.ViolationObject;
import org.boun.swe.ARCEONE.Static.PinpointType;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.graphics.Canvas;

public class ViolationPinpoint extends ItemizedOverlay<OverlayItem> {
	private AsyncTaskListener asyncTaskListener;
    private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
    private PinpointType pinpointType;
    private List<ViolationObject> violationList;

    public ViolationPinpoint(Context context, PinpointType pinpointType) {
        super(boundCenterBottom(context.getResources().getDrawable(getPinpointDrawable(pinpointType))));
        this.pinpointType = pinpointType;
        asyncTaskListener = (AsyncTaskListener)context;
    }
    
    private static int getPinpointDrawable(PinpointType pinpointType){
    	int drawable = R.drawable.img_pushpin_regular_location;
    	
    	if(PinpointType.Current.equals(pinpointType))
    		drawable = R.drawable.img_pushpin_current_location;
    	else if(PinpointType.Selected.equals(pinpointType))
    		drawable = R.drawable.img_pushpin_selected_location;
    	else if(PinpointType.Regular.equals(pinpointType))
    		drawable = R.drawable.img_pushpin_regular_location;
    	
    	return drawable;
    }
    
    public OverlayItem getViolation(int index) {
    	return pinpoints.get(index);
    }
    
    public List<ViolationObject> getViolationList(){
    	return violationList;
    }
    
    public void setViolationList(List<ViolationObject> violationList){
    	this.violationList = violationList;
    }

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		super.draw(canvas, mapView, false);
	}

    public void addOverlay(OverlayItem overlay){
        pinpoints.add(overlay);
        populate();
    }

    public void clearOverlays(){
        pinpoints.clear();
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return pinpoints.get(i);
    }

    @Override
    public int size() {
        return pinpoints.size();
    }
    
    protected boolean onTap(int index) {
    	asyncTaskListener.onTap(index, pinpointType);
        return true;
    }
}